package com.appheader.rongmaphone.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.appheader.rongmaphone.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class UserSecureFragment extends Fragment {

    private TextView phoneNum;

    public UserSecureFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_user_secure, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
    }

    private void initView(View view) {
        phoneNum = (TextView) view.findViewById(R.id.phone_num);
        String num = "13712342769";//假数据
        numSecure(num);
    }

    /**
     * 设置中间4位数字带星号的手机号码
     * @param pNumber
     */
    private void numSecure(String pNumber) {
        if(!TextUtils.isEmpty(pNumber) && pNumber.length() > 6 ){
            StringBuilder sb  =new StringBuilder();
            for (int i = 0; i < pNumber.length(); i++) {
                char c = pNumber.charAt(i);
                if (i >= 3 && i <= 6) {
                    sb.append('*');
                } else {
                    sb.append(c);
                }
            }
            phoneNum.setText(sb.toString());
        }
    }
}
